function findDOM(selector, timeout, interval) {
  return new Promise((resolve, reject) => {
    let startTime = Date.now();
    let endTime = startTime + timeout;

    let intervalId = setInterval(() => {
      if (Date.now() < endTime) {
        let element = document.querySelector(selector);
        if (element) {
          clearInterval(intervalId);
          resolve(element);
        }
      } else {
        clearInterval(intervalId);
        reject(new Error("超过指定时间，未找到指定元素"));
      }
    }, interval);
  });
}

findDOM("#myElement", 5000, 100).then((element) => {
  console.log("找到指定元素:", element);
}).catch((error) => {
  console.error("查找失败:", error);
})
